package com.qf.exec;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义异常处理器
 * @author fy
 * @version V1.0
 * @Project workspace
 * @Package com.qf.exec
 * @Description:
 * @Date 2022/6/15 17:08
 */
public class MyExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        //打印异常堆栈信息到日志
        e.printStackTrace();
        ModelAndView modelAndView = new ModelAndView();
        //返回给用户的提示信息
        modelAndView.addObject("error", "不好意思！网络繁忙求原谅");
        //设置页面的位置
        modelAndView.setViewName("error1");

        return modelAndView;
    }
}
